package com.hzhk.happyrent.ui.adapter.rent;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.BaseBean;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.ui.holder.rent.HomeCTopViewHolder;
import com.hzhk.happyrent.ui.holder.rent.HomeGridViewHolder;
import com.hzhk.happyrent.ui.holder.rent.HomeHeaderViewHolder;
import com.hzhk.happyrent.ui.holder.rent.HomeNewsViewHolder;


/**
 * User: hzhk(1097282555@qq.com)
 * Date: 2017/11/22
 * Time: 16:41
 * progject: HappyRent
 * Describe： ${Describe}
 */
public class RentLoadAdapter extends BaseAdapter<BaseBean> {

    public RentLoadAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        int type = getItemViewType(position);
        HomeHeaderViewHolder homeHeaderViewHolder;
        HomeGridViewHolder homeGridViewHolder;
        HomeCTopViewHolder homeCTopViewHolder;
        HomeNewsViewHolder homeNewsViewHolder;
        if (convertView == null) {
            switch (type) {
                case 0:
                    convertView = LayoutInflater.from(mContext).inflate(
                            R.layout.fragment_rent_header, null);
                    homeHeaderViewHolder = new HomeHeaderViewHolder(convertView, mContext);
                    homeHeaderViewHolder.setData(mList.get(position));
                    convertView.setTag(homeHeaderViewHolder);
                    break;
                case 1:
                    convertView = LayoutInflater.from(mContext).inflate(
                            R.layout.fragment_rent_type, null);
                    homeGridViewHolder = new HomeGridViewHolder(convertView, mContext);
                    homeGridViewHolder.setAction(mList.get(position));
                    convertView.setTag(homeGridViewHolder);
                    break;
                case 2:
                    convertView = LayoutInflater.from(mContext).inflate(
                            R.layout.fragment_rent_comm_top, null);
                    homeCTopViewHolder = new HomeCTopViewHolder(convertView, mContext,viewGroup);
                    homeCTopViewHolder.setAction(mList.get(position));
                    convertView.setTag(homeCTopViewHolder);
                    break;
                case 3:
                    convertView = LayoutInflater.from(mContext).inflate(
                            R.layout.fragment_rent_comm_news, null);
                    homeNewsViewHolder = new HomeNewsViewHolder(convertView, mContext);
                    homeNewsViewHolder.setAction(mList.get(position));
                    convertView.setTag(homeNewsViewHolder);
                    break;
            }
        } else {
            switch (type) {
                case 0:
                    homeHeaderViewHolder = (HomeHeaderViewHolder) convertView
                            .getTag();
                    homeHeaderViewHolder.setData(mList.get(position));
                    break;
                case 1:
                    homeGridViewHolder = (HomeGridViewHolder) convertView
                            .getTag();
                    homeGridViewHolder.setAction(mList.get(position));
                    break;
                case 2:
                    homeCTopViewHolder = (HomeCTopViewHolder) convertView
                            .getTag();
                    homeCTopViewHolder.setAction(mList.get(position));
                    break;
                case 3:
                    homeNewsViewHolder = (HomeNewsViewHolder) convertView
                            .getTag();
                    homeNewsViewHolder.setAction(mList.get(position));
            }

        }
        return convertView;
    }

    @Override
    public int getItemViewType(int position) {
        return mList.get(position).type;
    }

    @Override
    public int getViewTypeCount() {
        return 4;
    }

}
